package servlet;

import java.io.IOException;
import java.util.Date;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import pojo.Record;
import service.RecordManager;
import service.RecordManagerImpl;

/**
 * Servlet implementation class BuyConfirmServlet
 */
public class BuyConfirmServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public BuyConfirmServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		RecordManager rm = new RecordManagerImpl();
		List<Record> records = (List<Record>)request.getSession().getAttribute("records");
		for(Record r:records){
			if(r.getAmount()!=0){
				r.setRdate(new Date());
				rm.addRecord(r);
				r.setAmount(0);
			}
		}
		response.sendRedirect("showrecords");
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
